﻿using System;
using System.Collections.Generic;
using System.Text;
using jade.core;
using MarketSimulator.Utils.Maps;
using MarketSimulator.Utils.Attributes;
using System.Windows.Forms;
using MarketSimulator.Agents.Behaviors;

namespace MarketSimulator.Agents.Agents
{
    /// <summary>
    /// Storage Agent
    /// </summary>
    public class StorageAgent : Agent
    {
        public static int StorageAgentCount = 0;

        public Action<string> storageChat;

        public Action<string> actorsChat;

        private Form TheForm;

        public override void setup()
        {
            try
            {
                object[] args = getArguments();
                TheForm = args[0] as Form;
                storageChat = args[1] as Action<string>;
                actorsChat = args[2] as Action<string>;

                //Create Transporter info
                var storageNo = ++StorageAgentCount;
                var storageFacility = WorldMap.StorageFacilities[(storageNo - 1) % WorldMap.StorageFacilities.Count];
                StorageAttributes storageAttributes = new StorageAttributes(this, storageFacility, WriteToAgentsChat);
                storageAttributes.RegisterAgent();

                TheForm.Invoke(storageChat, string.Format("{0} : Storage Info = {1}", this.getLocalName(), storageAttributes.GetStorageInfoString()));

                //Add Behavior Section
                addBehaviour(new StorageBehavior(storageAttributes));
            }
            catch (Exception ex)
            {
                TheForm.Invoke(storageChat, ex.Message);
            }
           
        }

        public void WriteToAgentsChat(string message)
        {
            TheForm.Invoke(actorsChat, message);
        }
    }
}
